package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-17 11:41
 **/
public class _69_x的平方根 {

    public int mySqrt(int x) {
        if (x <= 1) {
            return x;
        }
        Integer pre = 1;
        for (int i = 1; i <= x / 2; i++) {
            int pow;
            if ((pow = i * i) < x) {
                pre = i;
            } else if (pow == x) {
                return i;
            } else {
                return pre;
            }

        }
        return pre;
    }


    public int mySqrt1(int x) {
        double sqrt = Math.sqrt(x);
        return (int) sqrt;
    }
}
